package src.CodeTopSecondPractice;

public class _202 {
    public boolean isHappy(int n) {
        int slow = n, fast = n;
        do {
            slow = getNext(slow);
            fast = getNext(getNext(fast));
        }while (slow != fast && fast != 1);
        return fast == 1;
    }

    public int getNext(int num) {
        int target = 0;
        while (num != 0) {
            target += (num % 10) * (num % 10);
            num /= 10;
        }
        return target;
    }
}
